{% extends 'base.html' %}
{% block title %}
用户中心
{% endblock %}

{% block head %}
<!--suppress JSUnresolvedLibraryURL -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
{% endblock%}

{% block middle %}

<div>
    <h1>所有用户信息如下：</h1>
    <label>
        搜索：
        <input type="text" name="search" placeholder="输入搜索内容">
    </label>
    <input type="button" value="搜索" id="search">
    {% if users %}
    <!--suppress HtmlDeprecatedAttribute -->
    <table border="1" cellspacing="0" width="50%">
        <tr>
            <th>序号</th>
            <th>用户名</th>
            <th>邮箱</th>
            <th>注册时间</th>
            <th>操作</th>
        </tr>
        {% for user in users %}
        <tr>
            <th><p style="color: #ff0000; font-size: 15px;">{{ loop.index }}</p></th>
            <th>{{ user.username }}</th>
            <th>{{ user.email }}</th>
            <th>{{ user.register_time}}</th>
            <th><!--suppress HtmlUnknownTarget -->
                <a href="{{ url_for('user.update_user') }}?id={{ user.id }}">更新</a><a> </a>
                <!--suppress HtmlUnknownTarget -->
                <a href="{{ url_for('user.del_user') }}?id={{ user.id }}">删除</a>
            </th>
        </tr>
        {% endfor %}
    </table>
    {% else %}
    <p style="color: #ff0000; font-size: 20px;">当前还没有任何用户</p>
    {% endif %}

</div>
{% endblock %}

{% block mys %}
<!--suppress JSUnusedGlobalSymbols -->
<script>
    function del(name) {
        location.href = '/user/del?username=' + name
    }

    function update(name) {
        location.href = '/user/update?username=' + name
    }

</script>
<!--suppress BadExpressionStatementJS, JSUnresolvedFunction, JSUnresolvedVariable -->
<script>
    // noinspection JSCheckFunctionSignatures
    $('#search').click(function () {
        let content = $("input[name='search']").val();
        location.href = '{{ url_for('
        user.search
        ') }}?search=' + content;
    })
</script>
{% endblock %}